package net.cloudcodex.client.character.view.panel;

import java.util.Map;

import net.cloudcodex.client.character.view.CharactersNoteView;
import net.cloudcodex.client.character.view.CharactersView.Message;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.dom.client.HasKeyDownHandlers;
import com.google.gwt.event.dom.client.HasKeyUpHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.IsWidget;

public class CharacterSheetDescriptionPanel extends FlowPanel {

	private final FlowPanel characteSheetPanel = new FlowPanel();
	private final CharacterSheetInfoPanel characterSheetInfoPanel = new CharacterSheetInfoPanel();
	private final CharacterSheetNotesPanel characterNotesPanel = new CharacterSheetNotesPanel();

	private boolean isGameMaster;
	private boolean isOwner;
	private Message message;
	private HorizontalPanel buttonsPanel = new HorizontalPanel();
	private Button popupCancelButton;
	private Button updateCharacterButton = new Button();

	public CharacterSheetDescriptionPanel() {

	}

	public void initComponent() {
		characterSheetInfoPanel.clear();
		characterSheetInfoPanel.setOwner(isOwner);
		characterSheetInfoPanel.setGameMaster(isGameMaster);
		characterSheetInfoPanel.setMessage(message);

		characteSheetPanel.add(characterSheetInfoPanel);
		characterSheetInfoPanel.initComponents();
		characterNotesPanel.setGameMaster(isGameMaster);
		characterNotesPanel.setOwner(isOwner);
		characterNotesPanel.setMessage(message);
		characterNotesPanel.initComponent();
		characteSheetPanel.add(characterNotesPanel);

		this.add(characteSheetPanel);
		this.add(buttonsPanel);
	}

	public void setOwner(boolean isOwner) {
		this.isOwner = isOwner;

	}

	public void setGameMaster(boolean isGameMaster) {
		this.isGameMaster = isGameMaster;
	}

	public void clearButtonPanel() {
		buttonsPanel.clear();
	}

	public void initUpdateCharacterButton() {
		updateCharacterButton.setEnabled(false);
		updateCharacterButton.setText(message.getUpdateCharacterButton());
		buttonsPanel.add(updateCharacterButton);
	}

	public HasClickHandlers getPopupCancelButton() {
		return popupCancelButton;
	}

	public HasClickHandlers getUpdateCharacterButton() {
		return updateCharacterButton;
	}

	public void initPopupCancelButton() {
		popupCancelButton = new Button();
		popupCancelButton.setText(message.getCancelButton());
		buttonsPanel.add(popupCancelButton);
	}

	public void addMessage(Message message) {
		this.message = message;

	}

	public void setUpdateCharacterNotesButtonEnable(boolean enable) {
		this.updateCharacterButton.setEnabled(enable);
	}

	public void addCharacterPublicDescription(String description) {
		characterSheetInfoPanel.addCharacterPublicDescription(description);
	}

	public void addCharacterPrivateDescription(String description) {
		characterSheetInfoPanel.addCharacterPrivateDescription(description);
	}

	public void addPersonalNote(CharactersNoteView charactersNoteView) {
		characterNotesPanel.addPersonalNotes(charactersNoteView);
	}

	public void addPlayersNote(CharactersNoteView charactersNoteView) {
		characterNotesPanel.addPlayersNotes(charactersNoteView);
	}

	public void addCharacter(long id, String icon, String name) {
		characterSheetInfoPanel.addCharacter(id, icon, name);
	}

	public void addAliases(Map<Long, String> aliases) {
		characterSheetInfoPanel.addAliases(aliases);
	}

	public HasKeyDownHandlers getPrivateDescriptionPanelKeyDownHandlers() {
		return characterSheetInfoPanel
				.getPrivateDescriptionPanelKeyDownHandlers();
	}

	public HasKeyUpHandlers getPrivateDescriptionPanelKeyUpHandlers() {
		return characterSheetInfoPanel
				.getPrivateDescriptionPanelKeyUpHandlers();
	}

	public HasKeyDownHandlers getPublicDescriptionPanelKeyDownHandlers() {
		return characterSheetInfoPanel
				.getPublicDescriptionPanelKeyDownHandlers();
	}

	public HasKeyUpHandlers getPublicDescriptionPanelKeyUpHandlers() {
		return characterSheetInfoPanel.getPublicDescriptionPanelKeyUpHandlers();
	}

	public void refreshPrivateDescriptions(String privateDescription) {
		this.characterSheetInfoPanel.refreshPrivateDescrption(privateDescription);
	}
	public void refreshPublicDescriptions(String publicDescription) {
		this.characterSheetInfoPanel.refreshPublicDescrption(publicDescription);
	}

	public void setOwnerId(Long ownerId) {
		this.characterSheetInfoPanel.setOwnerId(ownerId);
	}
	
	public CharacterSheetInfoPanel getCharacterSheetInfosPanel() {
		return this.characterSheetInfoPanel;
	}

	public CharacterSheetNotesPanel getCharacterSheetNotesPanel() {
		return characterNotesPanel;
	}
	public void addCharacterAdvancedInfos(boolean isProfile,boolean isLocked, boolean isDead){
		this.characterSheetInfoPanel.addCharacterAdvancedInfos(isProfile,isLocked,isDead);
	}
	public void isActive(boolean isActive){
		this.characterSheetInfoPanel.isActive(isActive);
	}

	public void addCancelButton(Button cancelButton) {
		popupCancelButton=cancelButton;
	}

	public Boolean isDead() {
		return characterSheetInfoPanel.isDead();
	}

	public Boolean isLocked() {
		// TODO Auto-generated method stub
		return characterSheetInfoPanel.isLocked();
	}

}
